package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

public class BibliotecaApp {

    Printer printer;
    private List<String> bookNames = new ArrayList<String>();
    private List<String> optionNames = new ArrayList<String>();

    public BibliotecaApp(PrintStream newPrintStream) {
        printer = new Printer(newPrintStream);

        bookNames.add("East of Eden");
        bookNames.add("Stumbling on Happiness");
        bookNames.add("Hitchhiker's Guide to the Galaxy");

        optionNames.add("List books");
        optionNames.add("Checkout book");
        optionNames.add("Return book");
    }

    public static void main(String[] args) {
        BibliotecaApp app = new BibliotecaApp(System.out);
        app.start();
    }

    public void start() {
        printer.print("Welcome\n");
        printer.print("List of books in the library:");
        printer.printList(bookNames);
        printer.print("Please select an option:");
        printer.printList(optionNames);
    }

    public String reactToOption(String s) {
        int intS = Integer.parseInt(s);
        if (intS <= 0 || intS > optionNames.size() ) {
            throw new IllegalArgumentException();
        }
        return optionNames.get(intS - 1);
    }
}
